var now = getNowFormatDateTime(); 
var username = sessionStorage.getItem("name");
var userid = sessionStorage.getItem("userId");
var repairid=GetQueryString("repairid");
var photoUrl = [];//拍照列表
var _config ;
$(document).ready(function(){
	$("#username").prepend(username);
	$("#repairid").append(repairid);
	$.ajax({
			url: '../../repair_info/getSelectBody'
			,type:'post'
			,dataType:'json'
			,contentType: "application/json; charset=utf-8"
			,data:JSON.stringify({"repairid":repairid})  
			,success: function(res){
				var resdata = res.data[0];
				$('#repairdate').val(resdata.repairdate);
				$('#shopcode').val(resdata.shopcode);
				$('#shopname').val(resdata.deptname);
				$('#tel').val(resdata.tel);
				$('#repairtype').val(resdata.name);
				$('#instruction').val(resdata.instruction);
				if(resdata.pic != "" && resdata.pic!= undefined){
				$('#paizhapoUrl .clearfix').remove()
				$('#paizhapoUrl').append('<div class="wig_img">'
					+'<div class="img_box">'
					+'<img alt="100x100" src="'+resdata.pic+'" onclick="showAllPic(\''+resdata.pic+'\')"/>'
					+'</div>'
					+'</div>');
				$('#paizhapoUrl').append('<div class="clearfix"></div>');
				}
			}
	});
});
$('#paizhao').on('click',function(){
	openphoto();
});
//打开钉钉拍照
function openphoto(){
	if(_config == undefined){
		$.ajax({
			type : "post",
			data:JSON.stringify({"pageUrl":location.href.replace(/\\&/g,'%26')}),
			contentType: "application/json; charset=utf-8",
			async: false,
			url : "../../dingding/getconfig",
			dataType : "json",
			success : function(suc) {
//				console.log(suc);
				_config = suc.config;
			}
		}); 
		dd.config({
			agentId : _config.agentid,
			corpId : _config.corpId,
			timeStamp : _config.timeStamp,
			nonceStr : _config.nonceStr,
			signature : _config.signature,
			jsApiList : [ 'runtime.info','biz.util.uploadImage' ]
		});
	}
	dd.ready(function(){
		dd.biz.util.uploadImage({
		    compression: false,//(是否压缩，默认为true)
		    quality: 100, // 图片压缩质量, 
		    resize: 100, // 图片缩放率
		    stickers: {   // 水印信息
		        time: getNowFormatDateTime(),
		        username: sessionStorage.getItem("name")
		    },
		    onSuccess : function(result) {
			photoUrl.push(result[0]);
			$('#paizhapoUrl .clearfix').remove()
			$('#paizhapoUrl').append('<div class="wig_img">'
					+'<div class="img_box">'
					+'<img alt="100x100" src="'+result[0]+'" onclick="showAllPic(\''+result[0]+'\')"/>'
					+'<img class="close_b" src="../../genius/style/mobile_page/assets/images/close.png" onclick="deletePhoto(this)">'
					+'</div>'
					+'</div>');
			$('#paizhapoUrl').append('<div class="clearfix"></div>');
		    },
		    onFail : function(err) {}
		});
	});
}	
//删除图片
function deletePhoto(obj){
	dd.device.notification.confirm({
	    message: "删除图片吗",
	    title: "提示",
	    buttonLabels: ['是', '否'],
	    onSuccess : function(result) {
	    	if(result.buttonIndex == '0'){
	    		var index = $(obj).parent().parent().index();
	    		$(obj).parent().parent().remove();
	    		photoUrl.splice(index,1);
	    	}
	        
	    },
	    onFail : function(err) {}
	});
	 
}
//预览图片
function showAllPic(imgOne){
	dd.biz.util.previewImage({
		urls: photoUrl,//图片地址列表
		current: imgOne,//当前显示的图片链接
		onSuccess : function(result) {
			/**/
		},
		onFail : function(err) {}
	})
}
function setshopname(shopcode){
	$.ajax({
			url: '../../repair_info/fillshopname'
			,type:'post'
			,dataType:'json'
			,contentType: "application/json; charset=utf-8"
			,data:JSON.stringify({'shopcode':shopcode})  
			,success: function(res){
				if(res.data.field != undefined){
					$('#shopname').val(res.data.field.deptname);
				}
				
			}
	});
}
